#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    umask(0);
    int fd = open("log.txt", O_WRONLY|O_CREAT|O_APPEND, 0666);//没有O_TRUNC
    if(fd < 0)
   {
       printf("open file error\n");
       return 1;
   }

    const char message[] = "追加语句\n";//自定义缓冲区
    ssize_t poi = write(fd, message, sizeof(message)-1);//无需把\0也写进文件中
    if (poi == -1) {  
        perror("write");  
        return -1;
    } 
    close(fd);
    return 0;
}